package com.sanyang.pda.ui.scancodequery;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.annotation.Nullable;


import com.alibaba.android.arouter.facade.annotation.Route;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.sanyang.pda.bean.ScanBean;
import com.sanyang.pda.bean.SearchStockDetailBean;
import com.sanyang.pda.contract.StockSearchContract;
import com.sanyang.pda.presenter.StockSearchPresenter;
import com.sanyang.pda.utils.StringConfig;
import com.sanyang.pda.view.ScanButView;
import com.wangshen.base.app.AppActivityKey;
import com.wangshen.base.ui.mvp.base.ui.BaseActivity;
import com.wangshen.base.ui.mvp.base.ui.BaseMvpActivity;
import com.wangshen.projectbase.R;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.RequestBody;

@Route(path = AppActivityKey.STOCKSEARCHACTIVITY)
public class StockSearchActivity extends BaseMvpActivity<StockSearchPresenter> implements StockSearchContract.View {
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.title)
    FrameLayout title;
    @BindView(R.id.scan)
    ScanButView scan;

    @Override
    public int getView() {
        return R.layout.activity_stocksearch;
    }

    @Override
    public void initView() {

    }

    @Override
    public void initLinsenterner() {

    }

    @Override
    public void getData() {

    }


    @OnClick(R.id.iv_back)
    public void onViewClicked() {
        finish();
    }

    @Override
    protected void onResume() {
        super.onResume();
        scan.setScanCallBack(new ScanButView.ScanCallBack() {
            @Override
            public void callBack(ScanBean scanBean) {
                if (scanBean.getType() == 2 || scanBean.getType() == 1){
                    presenter.inventoryQuery(scanBean.getCode());
                }
            }
        });
    }


    @Override
    protected void onPause() {
        super.onPause();
        scan.setScanCallBack(null);
    }

    @Override
    public StockSearchPresenter getPresenter() {
        return new StockSearchPresenter();
    }

    @Override
    public void setData(SearchStockDetailBean searchStockDetailBean) {
        Bundle bundle=new Bundle();
        bundle.putSerializable(StringConfig.BEAN,searchStockDetailBean);
        startIntent(AppActivityKey.STOCKDETAILACTIVITY,bundle);
    }
}
